package com.ygxsk.carhome.ui.adapter;

import android.view.View;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;

import com.allen.library.SuperTextView;
import com.blankj.utilcode.util.ColorUtils;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.chad.library.adapter.base.provider.BaseNodeProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.event.EventParkingInside;
import com.ygxsk.carhome.listener.DoubleClickListener;
import com.ygxsk.carhome.response.ParkingLicenseBean;

import org.greenrobot.eventbus.EventBus;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/1/6  10:31
 * @Description:第二层的布局
 */

public class SecondNodeProvider extends BaseNodeProvider {
    @Override
    public int getItemViewType() {
        return 1;
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_expandable_lv1;
    }

    @Override
    public void convert(@NonNull BaseViewHolder baseViewHolder, BaseNode data) {

        if (data != null) {

            //子条目的布局内容；
//            ItemNode entity = (ItemNode) data;

            ParkingLicenseBean parkingLicenseBean = (ParkingLicenseBean) data;

            if (parkingLicenseBean != null) {

                String cardName = parkingLicenseBean.getCarNo();

                SuperTextView textViewTwo = (SuperTextView) baseViewHolder.getView(R.id.textviewleveltwo);
                //设置顶部的分割线的颜色
                textViewTwo.setTopDividerLineColor(ColorUtils.getColor(R.color.gray30));

                FrameLayout frameImageView = (FrameLayout) baseViewHolder.getView(R.id.frameimageview);
                textViewTwo.setLeftString(cardName);
                textViewTwo.setLeftTextIsBold(true);
                textViewTwo.getLeftTextView().setLetterSpacing(0.1f);

                // 设置行间距为10dp
//                float lineSpacingExtra = 10;//getContext().getResources().getDimensionPixelSize(R.dimen.line_spacing_extra); // 自定义的行间距值
//                float lineSpacingMultiplier = 1.2f; // 行高乘数（默认为1）
//                textViewTwo.getLeftTextView().setLineSpacing(lineSpacingExtra, lineSpacingMultiplier);
//                textviewtwo.getLeftTextView().setLineSpacing(10f,1.2f);


                //添加删除的垃圾桶的点击事件
                frameImageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        if (!DoubleClickListener.isFastDoubleClick()) {

                            //这种貌似不可以
                            //LogUtils.d("itchen--删除了-" + cardName);

                            //使用消息发送
                            EventBus.getDefault().post(new EventParkingInside(//
                                    ExtraValue.EVENTBUS_PARKINGINSIDE_DELETE,//
                                    parkingLicenseBean.getParkingSpaceId(),//该车牌所在的车位信息
                                    parkingLicenseBean.getCarNoId(),
                                    parkingLicenseBean.getCarNo()));//该车牌的车牌字母数字

                        }
                    }
                });


            }

        }

    }
}
